<template>
  <div class="list-wrapper">
    <SearchTable :data="searchTableData"></SearchTable>
  </div>
</template>

<script>
import SearchTable from '../../components/search/SearchTable'
import { getSearchList } from '../../api/index'
import { setNavigationBarTitle, showToast } from '../../api/wechat'
export default {
  components: { SearchTable },
  mounted () {
    this.page = 1
    this.searchTableData = []
    this.getSearchList()
  },
  data () {
    return {
      searchTableData: [],
      page: 1
    }
  },
  // 生命周期：pages滑动到底部
  onReachBottom () {
    this.page = this.page + 1
    this.getSearchList()
  },
  methods: {
    async getSearchList () {
      const { key, text } = this.$route.query
      const params = {}
      if (key && text) {
        params[key] = text
      }
      params.page = this.page
      const { data: { data } } = await getSearchList(params)
      if (data && data.length > 0) {
        this.searchTableData.push(...data)
      } else {
        showToast('到底了，不要在滑了')
      }
      console.log(this.searchTableData)
      setNavigationBarTitle(text)
    }
  }
}
</script>

<style lang="scss" scoped>
</style>